/**
 * Created by soyomo on 17-8-28.
 */
angular.module('tribalc').controller('moreWelfareController',['$scope',
    '$rootScope',
    'Api',
    'Alert',
    '$state',

    function($scope,$rootscope,Api,Alert,$state) {
        $scope.goBackWelfare = goBackWelfare;
        $scope.gotoWelfareInfo = gotoWelfareInfo;
        $scope.getLocalTime = getLocalTime;
        $scope.getstatus = getstatus;
        $scope.prevPageClick=prevPageClick;
        $scope.nextPageClick=nextPageClick;
        $scope.nextSkip = null;
        $scope.hasMore = false;
        $scope.pageNum = 1;


        function goBackWelfare() {
            $state.go('company.companyWelfare');
        }
        function gotoWelfareInfo(id){
            $state.go('company.companyWelfareInfo',{welfareId:id});
        }
        function getstatus(status) {
            return{'FINISHED':'正常','':''}[status]
        }

        $scope.tableHeadItems = ['发放日期', '发放金额', '发放人数', '状态', '发放理由', '业务流水号'];
        getWelFareList(1,9);
        function getWelFareList(pageNum,pageSize) {
            Api.getWelfareList(null,pageNum,pageSize,function (result) {
                $scope.welfareList = result.data.content;
            });
        }
        function getLocalTime(nS) {
            var date = new Date(nS);
            Y = date.getFullYear() + '年';
            M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
            D = date.getDate() + '日';
            h = date.getHours() + ':';
            m = date.getMinutes();
            return Y + M + D ;
        }
        function prevPageClick() {
            if ($scope.pageNum != 1)
            {
                $scope.pageNum --;
                getWelFareList($scope.pageNum,9);
            }
            else {
                Alert.alertBox("已经是第一页",null);
            }
        }
        function  nextPageClick() {
            $scope.pageNum ++;
            Api.getWelfareList(null,$scope.pageNum,9,function (result) {
                if (result.data.content.length == 0)
                {
                    $scope.pageNum --;
                    Alert.alertBox("已经是最后一页",null);
                }
                else
                {
                    $scope.welfareList = result.data.content;
                }

            });

        }
    }
]);